<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <p>生命周期永久生效，多窗口共享（同一浏览器内），以键值对形式存在</p>
    <input type="text">
    <button class="set">存储数据</button>
    <button class="get">获取数据</button>
    <button class="remove">删除数据</button>
    <button class="del">清空所有数据</button>
</body>
<script>
    let input = document.querySelector("input");
    let set = document.querySelector(".set");
    let get = document.querySelector(".get");
    let remove = document.querySelector(".remove");
    let del = document.querySelector(".del");

    set.addEventListener('click', function(){
        localStorage.setItem('uname',input.value);
    });
    get.addEventListener('click', function(){
        let temp = localStorage.getItem('uname');
        console.log(temp);
    });
    remove.addEventListener('click', function(){
        localStorage.removeItem('uname');
    });
    del.addEventListener('click', function(){
        localStorage.clear();
    });
</script>
</html>